{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# Density of Floating Point Numbers\n",
        "\n",
        "This notebook enumerates all possible floating point nubmers in a floating point system and shows them in a plot to illustrate their density."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 2,
      "metadata": {
        "collapsed": true
      },
      "outputs": [],
      "source": [
        "import matplotlib.pyplot as pt\n",
        "import numpy as np"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 13,
      "metadata": {
        "collapsed": false
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "[  0.125       0.1328125   0.140625    0.1484375   0.15625     0.1640625\n",
            "   0.171875    0.1796875   0.1875      0.1953125   0.203125    0.2109375\n",
            "   0.21875     0.2265625   0.234375    0.2421875   0.25        0.265625\n",
            "   0.28125     0.296875    0.3125      0.328125    0.34375     0.359375\n",
            "   0.375       0.390625    0.40625     0.421875    0.4375      0.453125\n",
            "   0.46875     0.484375    0.5         0.53125     0.5625      0.59375\n",
            "   0.625       0.65625     0.6875      0.71875     0.75        0.78125\n",
            "   0.8125      0.84375     0.875       0.90625     0.9375      0.96875     1.\n",
            "   1.0625      1.125       1.1875      1.25        1.3125      1.375\n",
            "   1.4375      1.5         1.5625      1.625       1.6875      1.75\n",
            "   1.8125      1.875       1.9375      2.          2.125       2.25        2.375\n",
            "   2.5         2.625       2.75        2.875       3.          3.125       3.25\n",
            "   3.375       3.5         3.625       3.75        3.875       4.          4.25\n",
            "   4.5         4.75        5.          5.25        5.5         5.75        6.\n",
            "   6.25        6.5         6.75        7.          7.25        7.5         7.75\n",
            "   8.          8.5         9.          9.5        10.         10.5        11.\n",
            "  11.5        12.         12.5        13.         13.5        14.         14.5\n",
            "  15.         15.5        16.         17.         18.         19.         20.\n",
            "  21.         22.         23.         24.         25.         26.         27.\n",
            "  28.         29.         30.         31.       ]\n"
          ]
        },
        {
          "data": {
            "text/plain": [
              "[<matplotlib.lines.Line2D at 0x7f5020b580b8>]"
            ]
          },
          "execution_count": 13,
          "metadata": {},
          "output_type": "execute_result"
        },
        {
          "data": {
            "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX0AAAEACAYAAABfxaZOAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAErZJREFUeJzt3H+s5fVd5/HnC2ZAW9gpHQsuw68GayraFtMtpeu4HH90\n+WETBLOVGqVgYjCVrUlD026T3bnYkjgbdoOk0bFdiqAiaqtIbbNgZU4NmlKKDFCYAWoDDFOcGgWq\nsG0Q3vvH+V7mcL0/zr333Dn3zOf5SL653+/n+zmf73u+c+d1v+fzuWdSVUiS2nDYpAuQJB08hr4k\nNcTQl6SGGPqS1BBDX5IaYuhLUkOWDP0k1yXZn+T+Rfpcm+TRJLuSnD7UfmKS25I8lOSrSU4aV+GS\npOUb5Un/euDshU4mORc4tareAFwG7Bg6fSOwvapOA84AvrmKWiVJq7RhqQ5VdWeSkxfpcj6DcKeq\n7kqyKclxwGuBw6vqju7c8+MoWJK0cuOY098C7B063te1fT/wbJLPJLknyfYkGcP1JEkrtJYLuRuA\nrcAHgLcBpwKXrOH1JElLWHJ6ZwT7gBOHjk/o2jYCu6rqcYAktwBvZ7BG8ApJ/A+AJGkFqmpZMyij\nPumn2+ZzK3AxQJIzgWeqaj9wN/CaJJu7fj8OPLTQBapqardt27ZNvAbrn3wd1j992zTXXrWyZ+Ul\nn/ST3AT0gM1JngC2AUcMcro+UVWfT3Jekq8BzwGXdiH+UpIrgDu6qfx7gE+uqEpJ0liM8ts7PzdC\nn8sXaP9L4C0rqEuStAb8RO4Y9Hq9SZewKtY/WdY/OdNc+0plpfNCYy0iqfVQhyRNkyTUGi3kSpIO\nAYa+JDXE0Jekhhj6ktQQQ1+SGmLoS1JDDH1JaoihL0kNMfQlqSGGviQ1xNCXpIYY+pLUEENfkhpi\n6EtSQwx9SWqIoS9JDTH0Jakhhr4kNcTQl6SGGPqS1BBDX5IaYuhLUkMMfUlqiKEvSQ0x9CWpIYa+\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flu4J3AQwz+s8j/0nVbt/d/gfr3zN7/JGGwHrTo/Z/47+l3v971Gwx+\nAF1XVXP/W+Z1K8nrGTzdF4NFld9f7/UnuYnBh+k2A/uBbcAtwB8DJwKPA++uqmcmVeNiFqj/xxjM\nL78EPAZcNvv0s54k+RHgr4AHGHzPFPARBp9y/yPW+f1fpP6fYzru/5sYLNQe1m1/WFVXdf+ObwaO\nAe4Ffr57al5XFqn/L4HvYfAgtAv45aEF3387zqRDX5J08Ex6ekeSdBAZ+pLUEENfkhpi6EtSQwx9\nSWqIoS9JDTH0Jakhhr4kNeT/AybIFG8L7EMYAAAAAElFTkSuQmCC\n",
            "text/plain": [
              "<matplotlib.figure.Figure at 0x7f5020a4fe48>"
            ]
          },
          "metadata": {},
          "output_type": "display_data"
        }
      ],
      "source": [
        "significand_bits = 4\n",
        "exponent_min = -3\n",
        "exponent_max = 4\n",
        "\n",
        "fp_numbers = []\n",
        "for exp in range(exponent_min, exponent_max+1):\n",
        "    for sbits in range(0, 2**significand_bits):\n",
        "        significand = 1 + sbits/2**significand_bits \n",
        "        fp_numbers.append(significand * 2**exp)\n",
        "        \n",
        "fp_numbers = np.array(fp_numbers)\n",
        "print(fp_numbers)\n",
        "\n",
        "pt.plot(fp_numbers, np.ones_like(fp_numbers), \"+\")\n",
        "#pt.semilogx(fp_numbers, np.ones_like(fp_numbers), \"+\")\n",
        "        "
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": true
      },
      "outputs": [],
      "source": []
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.5.0+"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}